using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Acms.Bll;
using System.Collections.Generic;
using Telerik.Web.UI;

public partial class UserGeneratedContent_Comments : BaseUserGeneratedContentPage
{
    public override Acms.Bll.Role.Roles[] AllowedRoles
    {
        get { return new Acms.Bll.Role.Roles[] { Acms.Bll.Role.Roles.Developer, Acms.Bll.Role.Roles.UserGeneratedContentEditor, Acms.Bll.Role.Roles.ContentEditor, Acms.Bll.Role.Roles.ContentViewer }; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void dsComments_SelectData(object sender, Acms.DataControls.SelectEventArgs<Acms.Bll.UserPostComment> e)
    {
        List<UserPostComment> data = UserPostComment.GetAllByPostId(base.PostId);
        e.SetData(data);
    }

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.IsDataBound)
        {
        }

    }

    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if ((e.CommandName == "Approve" || e.CommandName == "Suspend") && e.CommandArgument != null)
        {
            int index = -1;
            try
            {
                index = int.Parse((string)e.CommandArgument);
            }
            catch
            {
            }
            if(index > -1)
            {
                int id = (int)RadGrid1.MasterTableView.DataKeyValues[index]["Id"];
                object concurencyId = RadGrid1.MasterTableView.DataKeyValues[index]["ConcurencyId"];
                UserPostComment comment = UserPostComment.GetById(id);
                if (comment != null)
                {
                    comment.CheckConcurent(concurencyId);
                    if (e.CommandName == "Approve")
                    {
                        comment.Approve();
                    }
                    else if (e.CommandName == "Suspend")
                    {
                        comment.Suspend();
                    }
                    comment.Update();
                }
                RadGrid1.Rebind();
            }
        }
    }
}
